<?php defined('BASEPATH') OR exit('No direct script access allowed');

class User_m extends CI_Model {

    public function __construct()
    {
        parent::__construct();
    }
    
    public function update($fields = array(), $conditions = array())
    {
        if (empty ($fields) || empty ($conditions))
        {
            return false;
        }
        
        $this->db->update('iemvn_users', $fields, $conditions);
        
        //@TODO: clear cache;
        
        return $this->db->affected_rows();
    }
    
    /**
     * Get user by id
     * @param int $user_id
     * @return array 
     */
    public function get_by_id($user_id)
    {
        //@TODO: apply cache here
        return $this->db->query("SELECT * FROM iemvn_users WHERE id = ?", array($user_id))->row_array();
    }
    
    /**
     * Get profile user by id
     * @param int $user_id
     * @return array 
     */
    public function get_profile($user_id)
    {
        //@TODO: apply cache here
        return $this->db->query("SELECT * FROM iemvn_profiles WHERE user_id = ?", array($user_id))->row_array();
    }

}

